$(document).ready(function () {
 var language_type = localStorage.getItem("language_type");
 var d_type = 1; // 头部tab切换 1-养殖中 2-配对中
 $(".weishi_tab").click(function(){
  d_type = $(this).attr("data-type");
  $(this).addClass("jui_tab_on");
  $(this).siblings().removeClass("jui_tab_on");
  getList();
 })
 getList();
 function getList(){
  var data = {
   uid: localStorage.getItem("u_id"),
   token: localStorage.getItem("token"),
   language_type: language_type,
   d_type: d_type
  }
  $.ajax({
   type: 'post',
   url: baseURL + '/index.php?m=user&c=receive_list',
   data: data,
   success: function success(data) {
    data = JSON.parse(data);
    is_login(data);
    if(data.code == 1){
     layer.closeAll();
     let time = data.time // 获取当前的时间戳
     let detailsList = '';
     if (data.data.length == 0) {
      detailsList = `<div class="if_null">
         <img class="if_null_img" src="./icons/nothing.png" alt="">
         <div class="if_null_text col_000 f30" data-ch="暂无内容" data-en="No data">暂无内容</div>
        </div>`
     } else {
      data.data.forEach(function (item) {
       detailsList += `<div class="jui_flex gm_list_con jui_bor_rad_15" style="${d_type == 1 ? '' : 'display:none'}">
           <img class="jui_align_self_center gm_list_img" src="${item.d_img}">
           <div class="jui_flex1 gm_list_text">
            <P>
             <span class="col_fff" data-ch="恐龙种类：" data-en="Dino type:">恐龙种类：</span>
             <span>${item.d_name}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="买入：" data-en="Buy:">买入：</span class="col_fff">
             <span>${item.d_price}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="卖出：" data-en="Sell:">卖出：</span class="col_fff">
             <span>${item.d_nprice}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="捕猎日期:" data-en="Hunt date:">捕猎日期：</span class="col_fff">
             <span>${item.d_s_date}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="成熟日期:" data-en="Mature date:">成熟日期：</span class="col_fff">
             <span>${item.d_e_date}</span>
            </P>
           </div>
           <div class="gm_list_right jui_flex_col_center">
            <div class="gm_list_btn guamai ${item.d_feed < 1 ? "" : "jui_bg_b1"}" data-id="${item.id}" data-time1="${item.d_profit_end}" data-ch="挂卖" data-en="Sell">挂卖</div>
            <div class="gm_list_btn weishi_btn ${item.d_feed < 1 ? "jui_bg_b1" : ""}" data-id="${item.id}" data-ch="喂食" data-en="Feed">喂食</div>
            <div class="jui_flex_row_center">
             <img class="gm_list_icon" src="icons/nav_icon02.png">
             <p class="col_fff" data-feed="${item.d_feed}">×${item.d_feed}</p>
            </div>
           </div>
          </div>
          <div class = "jui_flex gm_list_con jui_bor_rad_15" style="${d_type == 2 ? '' : 'display:none'}">
           <img class="jui_align_self_center gm_list_img" src="${item.d_img}">
           <div class="jui_flex1 gm_list_text">
            <P>
             <span class="col_fff" data-ch="恐龙种类：" data-en="Dino type:">恐龙种类：</span class="col_fff">
             <span>${item.d_name}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="买入：" data-en="Buy:">买入：</span class="col_fff">
             <span>${item.d_price}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="卖出：" data-en="Sell:">卖出：</span class="col_fff">
             <span>${item.d_nprice}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="捕猎日期：" data-en="Hunt date:">捕猎日期：</span class="col_fff">
             <span>${item.d_s_date}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="成熟日期：" data-en="Mature date:">成熟日期：</span class="col_fff">
             <span>${item.d_e_date}</span>
            </P>
            <P>
             <span class="col_fff" data-ch="挂卖日期：" data-en="Sale date:">挂卖日期：</span class="col_fff">
             <span>${item.d_m_date}</span>
            </P>
           </div>
           <div class="gm_list_right  weishi_details_box_center">
            <p class="col_fff" data-ch="配对中" data-en="Matching">配对中</p>
           </div>
          </div>`
      })
     }
     $(".weishi_details").html(detailsList);
     language()
     $(".guamai").click(function(){ // 挂卖
      var endTime = $(this).attr("data-time1"); // 成熟日期时间戳
      console.log(time > Number(endTime));
      if (time > Number(endTime)) { // 只有当前时间戳大于成熟日期时间戳时, 按钮可以点击
       var data1 = {
        uid: localStorage.getItem("u_id"),
        token: localStorage.getItem("token"),
        language_type: language_type,
        d_id: $(this).attr("data-id")
       }
       $.ajax({
        type: 'post',
        url: baseURL + '/index.php?m=user&c=set_sale',
        data: data1,
        success: function success(data) {
         data = JSON.parse(data);
         is_login(data);
         if(data.code == 1){
          setTimeout(function(){
           getList()
          }, 1000);
         }
         box_timer(data.msg)
        }
       })
      } else {
       box_timer(language_type == 1 ? '没有成熟的恐龙无法挂卖哦' : "No mature dinosaur can be sell")
      }
     })
     $(".weishi_btn").click(function(){ // 喂食
      var data1 = {
       uid: localStorage.getItem("u_id"),
       token: localStorage.getItem("token"),
       language_type: language_type,
       d_id: $(this).attr("data-id")
      }
      $.ajax({
       type: 'post',
       url: baseURL + '/index.php?m=index&c=deal_feed',
       data: data1,
       success: function success(data){
        data = JSON.parse(data);
        is_login(data);
        box_timer(data.msg);
        if(data.code == 1){
        	setTimeout(function () {
			  window.location.href = 'weishi.html';
			}, 1500);
        	
        }
       }
      })

     })

    }
   }
  })
 }


 language();
 documentName()
});